local canying = fk.CreateSkill {
  name = "wk_heg__canying",
}

Fk:loadTranslationTable{
  ["wk_heg__canying"] = "残荧",
  [":wk_heg__canying"] = "每回合结束时，若你本回合对其他角色使用过红色牌，你可以对一名体力值不为最小的角色造成1点火焰伤害。",

  ["#wk_heg__canying-choose"] = "残荧：你可以选择一名体力值不为最小的角色，对其造成1点火焰伤害",
}

canying:addEffect(fk.TurnEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(canying.name) then return false end
    return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        local use = e.data
        if use.from == player and use.card and use.card.color == Card.Red and table.find(use.tos, function(p) return p ~= player end) then
          return true
        end
      end, Player.HistoryTurn) > 0 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local minHp = 100
    for _, p in ipairs(room.alive_players) do
      if p.hp < minHp then
        minHp = p.hp
      end
    end
    local targets = table.filter(room.alive_players, function (p) return p.hp > minHp end)
    local to = room:askToChoosePlayers(player,{
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#wk_heg__canying-choose",
      skill_name = canying.name,
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {to = to[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).to
    player.room:damage{
      from = player,
      to = to,
      damage = 1,
      damageType = fk.FireDamage,
      skillName = canying.name,
    }
  end,
})

return canying